package kgame5.kutil {
	import flash.utils.getTimer;

	/**
 * @author kk
 * 一个安全的计时器，被每帧更新,定时结束则返回true.
 * 注意这个是比ProcessManager.schdule要安全的东西，可以保证在状态机GState不被运行的时候会关闭
 */
public class SafeTimer {
	private var durMS:int;
	
	private var startTimeMS:int;
	
	private var running:Boolean=false;
	
	public function SafeTimer(){
	}
	
	public function start(durMS:int):void{
		this.durMS=durMS;
		startTimeMS=getTimer();
		running=true;
	}
	
	//每帧返回
	public function isOK():Boolean{
		if(running==false){
			return false;
		}
		var curTimeMS:int=getTimer();
		if(curTimeMS-startTimeMS>=durMS){
			return true;
		}
		return false;
	}
	public function stop():void{
		running=false;
	}
}//end of class
}
